﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XTrace
{
	/// <summary>
	/// Combine several sources, and several listeners
	/// </summary>
	public class XTraceSourcesBundle
	{
		public void AddSource(XTraceSource source)
		{
			lock (_sources)
			{
				if (!_sources.Contains(source))
				{
					_sources.Add(source);
					source.AddBundle(this);
				}
			}
		}

		public void AddListener(XTraceListener listener)
		{
			lock (_listeners)
			{
				if (!_listeners.Contains(listener))
				{
					_listeners.Add(listener);
					listener.AddBundle(this);
				}
			}
		}

		readonly List<XTraceSource> _sources = new List<XTraceSource>();
		public IEnumerable<XTraceSource> Sources
		{
			get
			{
				lock (_sources)
				{
					return _sources.ToArray();
				}
			}
		}

		readonly List<XTraceListener> _listeners = new List<XTraceListener>();
		public IEnumerable<XTraceListener> Listeners
		{
			get
			{
				lock (_listeners)
				{
					return _listeners.ToArray();
				}
			}
		}
	}
}
